package com.smartwebx.fr.util;

import java.util.List;
import java.util.Map;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.smartwebx.fr.bean.mysql.PageUseArg;

public class CurrLocalSeIdUseParam {
	private static ThreadLocal<List<PageUseArg>> currentThread = new ThreadLocal<List<PageUseArg>>();

	private static Map<String, List<PageUseArg>> map = Maps.newHashMap();

	public static void switchOrNewThread(String sessionId) {
		if (sessionId == null)
			return;
		List<PageUseArg> useArgs = map.get(sessionId);
		currentThread.set(useArgs);
	}

	public static void putUseParams(String sessionId,
			List<PageUseArg> pageUseArgs) {
		map.put(sessionId, pageUseArgs);
	}

	public static List<PageUseArg> getPageUseArgs() {
		List<PageUseArg> result = Lists.newArrayList();
		if (currentThread != null && currentThread.get() != null) {
			result = currentThread.get();
		}
		return result;
	}

	public static void removePageUseArgsBySessionId(String sessionId) {
		if (sessionId != null)
			map.remove(sessionId);
	}
}
